package com.hlhj.carview.aty

import android.content.Intent
import android.net.Uri
import android.widget.Toast
import com.hlhj.carview.BaseAty
import com.hlhj.carview.Constant
import com.hlhj.carview.Iview.AddEquipmentView
import com.hlhj.carview.R
import com.hlhj.carview.bean.MyBaseBean
import com.hlhj.carview.presenter.AddEquipmentPresenter
import com.hlhj.carview.utils.ToastUtil
import kotlinx.android.synthetic.main.aty_addequipment.*
import kotlinx.android.synthetic.main.lo_pubhead.*

/**
 * Created by Never Fear   on 2018\12\24 0024.
Never More....
 */
class AskEquipmentAty :BaseAty<AddEquipmentView,AddEquipmentPresenter>(), AddEquipmentView {
    override fun setRepair(myBaseBean: MyBaseBean) {

    }

    override fun setAddResult(myBaseBean: MyBaseBean) {
        ToastUtil.toast(myBaseBean.msg.toString(),this)
        finish()
    }

    override fun initView() {
        tvTittle.text="申请设备"
        btRightIcon.setImageResource(R.drawable.ic_grzx_kf)

    }

    override fun logicStart() {

    }

    override fun setListener() {
        btCommit.setOnClickListener {
            if (etName.text.isEmpty()){
                ToastUtil.toast("请填写名称",this)
                return@setOnClickListener
            }
            if (etPhone.text.isEmpty()){
                ToastUtil.toast("请填写手机号码",this)
                return@setOnClickListener
            }
            if (etWechat.text.isEmpty()){
                ToastUtil.toast("请填写微信",this)
                return@setOnClickListener
            }
            presenter?.addEquipment(etName.text.toString(),etPhone.text.toString(),etWechat.text.toString(),this)
        }
        btRightIcon.setOnClickListener {
            // 打电话
            // Intent : 意图.我想去做一件事
            val t = Intent()
            // Action:动作.我具体想做什么事
            // Intent.ACTION_DIAL: 激活拨号界面
            // Intent.ACTION_CALL: 直接拨打电话
            t.action = Intent.ACTION_CALL
            // Data: 数据.具体的动作所需要的附加数据
            //封装一个拨打电话的intent，并且将电话号码包装成一个Uri对象传入
            t.data = Uri.parse("tel:" + Constant.phone)
            // 通知系统你去帮我干活吧
            startActivity(t)
        }
    }

    override fun bindView(): AddEquipmentView {
        return this
    }

    override fun createPresenter(): AddEquipmentPresenter {
        return AddEquipmentPresenter()
    }

    override fun getContentID(): Int {
        return R.layout.aty_addequipment
    }
}